import 'package:equatable/equatable.dart';
import 'package:backend.core/core/domain/entities/api/google_play/api_google_play_transaction_revocation_info.dart';
import 'package:backend.purchases/infrastructure/dtos/api/api_time_dto.dart';
import 'package:backend.purchases/infrastructure/dtos/api/google_play/api_google_play_transaction_revocation_reason_dto.dart';
import 'package:backend.purchases/infrastructure/dtos/api/google_play/api_google_play_transaction_revocation_source_dto.dart';

const kApiGooglePlayTransactionRevocationSourceKey = 'source';
const kApiGooglePlayTransactionRevocationReasonKey = 'reason';
const kApiGooglePlayTransactionRevocationTimeKey = 'time';

class ApiGooglePlayTransactionRevocationInfoDto extends Equatable {
  const ApiGooglePlayTransactionRevocationInfoDto._internal({
    required this.sourceDto,
    required this.reasonDto,
    required this.timeDto,
  });

  final ApiGooglePlayTransactionRevocationSourceDto sourceDto;
  final ApiGooglePlayTransactionRevocationReasonDto reasonDto;
  final ApiTimeDto timeDto;

  @override
  List<Object?> get props {
    return [
      sourceDto,
      reasonDto,
      timeDto,
    ];
  }

  factory ApiGooglePlayTransactionRevocationInfoDto.fromEntity(
      ApiGooglePlayTransactionRevocationInfo revocationInfo) {
    final sourceDto = ApiGooglePlayTransactionRevocationSourceDto.fromEntity(revocationInfo.source);
    final reasonDto = ApiGooglePlayTransactionRevocationReasonDto.fromEntity(revocationInfo.reason);
    final timeDto = ApiTimeDto.fromEntity(revocationInfo.time);

    return ApiGooglePlayTransactionRevocationInfoDto._internal(
      sourceDto: sourceDto,
      reasonDto: reasonDto,
      timeDto: timeDto,
    );
  }

  Map<String, dynamic> toJson() {
    return {
      kApiGooglePlayTransactionRevocationSourceKey: sourceDto,
      kApiGooglePlayTransactionRevocationReasonKey: reasonDto,
      kApiGooglePlayTransactionRevocationTimeKey: timeDto.toString(),
    };
  }
}
